<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>章节管理</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    <table class="layui-table" onsubmit="return false">
        <colgroup>
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>章节名</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $result as $val}
        <input type="text" value="{$val.id}" hidden>
        <tr>
            <td>{$val.zjtitle}</td>
            <td>
                <button class="layui-btn layui-btn-normal" value="{$val.id}"  name="video">章节视频</button>&nbsp;&nbsp;&nbsp;&nbsp;
                <button class="layui-btn layui-btn-danger" value="{$val.id}" name="del">删除章节</button>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    <button class="layui-btn layui-btn-warm" id="add" value="{$message.id}">添加章节</button>
</body>
</html>
<script>
    //章节视频
    $("button[name=video]").click(function(){
        var id = $(this).val();
        window.location.href ="{:url('/video/videoList')}?id="+id;
    })
    //添加章节
    $("#add").click(function(){
        var id = $(this).val();
        layer.prompt({title: '请输入章节名称'},function(val,index){
            $.ajax({
                url:"{:url('/video/addSectionMessage')}",
                data:{zjtitle:val,cat_id:id},
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                        return;
                    }else{

                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }
            })
            layer.close(index);
        });
    })
    //删除章节
    $("button[name=del]").click(function(){
        var id = $(this).val()
        layer.confirm('确认删除此章节？', {
            btn: ['是的','不'] //按钮
        }, function(){
            $.ajax({
                url:"{:url('/video/delSection')}",
                data:{id:id},
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }

            })
        })

    })
</script>